﻿using SharpDX.D3DCompiler;
using System.Configuration;
using System.Data;
using System.IO;
using System.Windows;

namespace WpfShaderEffect
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            //CompileHLSLToBytecode("ShaderEffect.hlsl", "ShaderEffect.ps");
        }

        public static void CompileHLSLToBytecode(string inputFilePath, string outputFilePath)
        {
            // 读取HLSL源代码
            string hlslSourceCode = File.ReadAllText(inputFilePath);

            // 编译HLSL源代码到字节码
            var result = ShaderBytecode.Compile(hlslSourceCode, "main", "ps_2_0");

            // 将字节码写入到文件
            using (FileStream outputFileStream = new FileStream(outputFilePath, FileMode.Create))
            {
                outputFileStream.Write(result.Bytecode, 0, result.Bytecode.Data.Length);
            }
        }
    }
}
